// JavaScript Document
$(function(){

	var Good = Backbone.Model.extend({
	
		// Default attributes for a todo item.
		defaults: function() {
		  return {
			done:  false,
			url:function(e){
				console.log(e);
			},
			id:1
		  };
		},
		urlRoot:"/Good"
	});
	
	var GoodList = Backbone.Collection.extend({
		model:Good,
		url:"/data.php?action=left",
		parse:function(json){
			console.log(json);
			if(json.success){
				this.pageIndex = json.result.page;
				this.total = json.result.total;
				this.reset(json.result.items);
			}
		},
		pageSize:6
		});
	
	window.goodList = new GoodList;
	goodList.add(new Good({name:"zmw"}));
	goodList.add(new Good({name:"lsd"}));
	var GoodView = Backbone.View.extend({
		tagName: "li",
		template: _.template($('#J_Tmpl_Good').html()),
		events:{},
		initialize: function() {
		  this.model.bind('change', this.render, this);
		},
		render: function() {
		  $(this.el).html(this.template(this.model.toJSON()));
		  return this;
		},
	});
	
	var LikePageView = Backbone.View.extend({
		el:$("#J_GoodList"),
		initialize:function(){
			goodList.fetch({data:{page:2}});
		}
		
	});
	
	var like = new LikePageView;
});